<?php
namespace addons\prl\taglib;
use think\template\TagLib;
class Article extends TagLib{
	/**
     * 定义标签列表
     */
    protected $tags   =  [
        'getlistarticles'     => ['attr' => 'channel_id,limit,item', 'close' => 1], //获取指定栏目(类型 列表)下的文章
        'getchannellistarticles'     => ['attr' => 'channel_id,limit,item', 'close' => 1], //获取指定栏目(类型 列表)下的文章
    ];

    /**
     * 获取指定栏目(类型 列表)下的文章
     * @param channel_id 指定栏目id
     * @param limit      条数
     * @param item       变量
     */
    public function tagGetlistarticles($tag, $content)
    {
    	$channel_id = empty($tag['channel_id']) ? '' : $tag['channel_id'];
        $limit = empty($tag['limit']) ? 5 : $tag['limit'];
        $item  = empty($tag['item']) ? 'vo' : $tag['item'];//循环变量名
        $parse = <<<parse
<?php
    \$__ARTICLES_ITEMS__ = \addons\prl\service\Articles::getList('{$channel_id}',{$limit});
?>
{volist name="__ARTICLES_ITEMS__" id="{$item}"}
{$content}
{/volist}
parse;
        return $parse;
    }

    /**
     * 获取指定栏目(类型 栏目)下的文章
     * @param channel_id 指定栏目id
     * @param limit      条数
     * @param item       变量
     */
    public function tagGetchannellistarticles($tag, $content)
    {
        if(empty($tag['channel_id'])){
            return false;
        }
        $channel_id = $this->autoBuildVar($tag['channel_id']);
        $limit = empty($tag['limit']) ? 5 : $tag['limit'];
        $item  = empty($tag['item']) ? 'vo' : $tag['item'];//循环变量名
        $parse = <<<parse
<?php
    \$channel_id = {$channel_id};
    \$__ARTICLES_ITEMS__ = \addons\prl\service\Articles::getChannelList(\$channel_id,{$limit});
?>
{volist name="__ARTICLES_ITEMS__" id="{$item}"}
{$content}
{/volist}
parse;
        return $parse;
    }
}